

class DpdController < ApplicationController  
require "gchart"  

  def dpd_summary
    # Setup the webservice request parameters
    dpd_host = params[:host]
    user = session[:user] 
    password= session[:pass]
    project = 'Default'
    
    # Create the timestamp string used to get the dpd info.
    year = params[:date][:year]
    month = params[:date][:month]
    day = params[:date][:day] 
    
    if month.length == 1
      month = '0' + month
    end 
    if day.length == 1
      day = '0' + day
    end
    timestamp =  year + '-'+  month+ '-' + day + 'T00:00:00.000'
    
    dpd_consumer = DpdConsumer.new(dpd_host, 'codeissue', user, project, timestamp, password)
    @code_issue_dpd = dpd_consumer.get_representation    
    
    dpd_consumer = DpdConsumer.new(dpd_host, 'unittest', user, project, timestamp, password)
    @unit_test_dpd = dpd_consumer.get_representation    
    
    #    code_issue_consumer = DpdConsumer.new(dpd_host, 'build', user, project, timestamp, password)
    #    @build_dpd = code_issue_consumer.get_representation    
    #    
    #    code_issue_consumer = DpdConsumer.new(dpd_host, 'commit', user, project, timestamp, password)
    #    @commit_dpd = code_issue_consumer.get_representation    
  end
  
  def save_projects
    user = params[:user]
    pass = params[:password]
#    session[:user] = user
#    session[:pass] = pass
    project_consumer =ProjectConsumer.new(params[:sensorbase_host], user, pass)
    projects = project_consumer.get_projects
    redirect_to :action => 'dpd_selector', :projects => projects, :user => user, :pass => pass
  end
  
  def dpd_selector
    @projects = params[:projects]
  end
end
